{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# PyTorch网络结构可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.使用torchviz库进行可视化\n",
    "\n",
    "参考[github](https://github.com/szagoruyko/pytorchviz/blob/master/examples.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch.autograd import Variable\n",
    "import torch.nn as nn\n",
    "from torchvision import models\n",
    "from torchviz import make_dot, make_dot_from_trace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class CNN(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(CNN, self).__init__()\n",
    "        self.conv1 = nn.Sequential(\n",
    "            nn.Conv2d(in_channels=1, out_channels=16, kernel_size=5, stride=1, padding=2),\n",
    "            nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=2)\n",
    "        )\n",
    "        self.conv2 = nn.Sequential(\n",
    "            nn.Conv2d(in_channels=16, out_channels=32, kernel_size=5, stride=1, padding=2),\n",
    "            nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=2)\n",
    "        )\n",
    "        self.out = nn.Linear(32*7*7, 10)\n",
    " \n",
    "    def forward(self, x):\n",
    "        x = self.conv1(x)\n",
    "        x = self.conv2(x)\n",
    "        x = x.view(x.size(0), -1)  # (batch, 32*7*7)\n",
    "        out = self.out(x)\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: %3 Pages: 1 -->\r\n",
       "<svg width=\"473pt\" height=\"524pt\"\r\n",
       " viewBox=\"0.00 0.00 473.00 524.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 520)\">\r\n",
       "<title>%3</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-520 469,-520 469,4 -4,4\"/>\r\n",
       "<!-- 2302943132976 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>2302943132976</title>\r\n",
       "<polygon fill=\"#caff70\" stroke=\"black\" points=\"347,-21 234,-21 234,-0 347,-0 347,-21\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-7.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ThAddmmBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133032 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>2302943133032</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"217.5,-78 119.5,-78 119.5,-57 217.5,-57 217.5,-78\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"168.5\" y=\"-64.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ExpandBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133032&#45;&gt;2302943132976 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>2302943133032&#45;&gt;2302943132976</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M189.751,-56.9197C209.138,-48.1798 238.012,-35.1625 259.886,-25.3014\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"261.405,-28.4557 269.083,-21.155 258.529,-22.0742 261.405,-28.4557\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133368 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>2302943133368</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"185.5,-148 131.5,-148 131.5,-114 185.5,-114 185.5,-148\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"158.5\" y=\"-134.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">out.bias</text>\r\n",
       "<text text-anchor=\"middle\" x=\"158.5\" y=\"-121.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (10)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133368&#45;&gt;2302943133032 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>2302943133368&#45;&gt;2302943133032</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M161.127,-113.842C162.415,-105.923 163.976,-96.3241 165.329,-88.0006\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"168.798,-88.474 166.948,-78.0419 161.889,-87.3505 168.798,-88.474\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133088 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>2302943133088</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"334.5,-78 246.5,-78 246.5,-57 334.5,-57 334.5,-78\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-64.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ViewBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133088&#45;&gt;2302943132976 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>2302943133088&#45;&gt;2302943132976</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.5,-56.9197C290.5,-49.9083 290.5,-40.1442 290.5,-31.4652\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"294,-31.3408 290.5,-21.3408 287,-31.3409 294,-31.3408\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133144 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>2302943133144</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"377.5,-141.5 203.5,-141.5 203.5,-120.5 377.5,-120.5 377.5,-141.5\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-127.9\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">MaxPool2DWithIndicesBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133144&#45;&gt;2302943133088 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>2302943133144&#45;&gt;2302943133088</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.5,-120.391C290.5,-111.866 290.5,-99.1392 290.5,-88.4235\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"294,-88.2448 290.5,-78.2449 287,-88.2449 294,-88.2448\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133648 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>2302943133648</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"348,-205 233,-205 233,-184 348,-184 348,-205\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-191.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ThresholdBackward0</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133648&#45;&gt;2302943133144 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>2302943133648&#45;&gt;2302943133144</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.5,-183.891C290.5,-175.366 290.5,-162.639 290.5,-151.923\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"294,-151.745 290.5,-141.745 287,-151.745 294,-151.745\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943132808 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>2302943132808</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"353,-262 228,-262 228,-241 353,-241 353,-262\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-248.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ThnnConv2DBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943132808&#45;&gt;2302943133648 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>2302943132808&#45;&gt;2302943133648</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.5,-240.92C290.5,-233.908 290.5,-224.144 290.5,-215.465\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"294,-215.341 290.5,-205.341 287,-215.341 294,-215.341\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133536 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>2302943133536</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"229.5,-325.5 55.5,-325.5 55.5,-304.5 229.5,-304.5 229.5,-325.5\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"142.5\" y=\"-311.9\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">MaxPool2DWithIndicesBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133536&#45;&gt;2302943132808 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>2302943133536&#45;&gt;2302943132808</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M165.625,-304.391C190.497,-294.055 230.23,-277.545 258.184,-265.928\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"259.646,-269.111 267.537,-262.042 256.96,-262.647 259.646,-269.111\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302908654088 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2302908654088</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"200,-389 85,-389 85,-368 200,-368 200,-389\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"142.5\" y=\"-375.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ThresholdBackward0</text>\r\n",
       "</g>\r\n",
       "<!-- 2302908654088&#45;&gt;2302943133536 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>2302908654088&#45;&gt;2302943133536</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M142.5,-367.891C142.5,-359.366 142.5,-346.639 142.5,-335.923\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"146,-335.745 142.5,-325.745 139,-335.745 146,-335.745\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302908654256 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>2302908654256</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"205,-446 80,-446 80,-425 205,-425 205,-446\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"142.5\" y=\"-432.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ThnnConv2DBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302908654256&#45;&gt;2302908654088 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2302908654256&#45;&gt;2302908654088</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M142.5,-424.92C142.5,-417.908 142.5,-408.144 142.5,-399.465\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"146,-399.341 142.5,-389.341 139,-399.341 146,-399.341\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302908654816 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>2302908654816</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"81,-516 0,-516 0,-482 81,-482 81,-516\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"40.5\" y=\"-502.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">x</text>\r\n",
       "<text text-anchor=\"middle\" x=\"40.5\" y=\"-489.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (1, 1, 28, 28)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302908654816&#45;&gt;2302908654256 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>2302908654816&#45;&gt;2302908654256</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M67.2993,-481.842C82.9409,-472.411 102.536,-460.596 117.803,-451.391\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"119.918,-454.203 126.674,-446.042 116.303,-448.208 119.918,-454.203\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302908655320 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>2302908655320</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"185.5,-516 99.5,-516 99.5,-482 185.5,-482 185.5,-516\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"142.5\" y=\"-502.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">conv1.0.weight</text>\r\n",
       "<text text-anchor=\"middle\" x=\"142.5\" y=\"-489.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (16, 1, 5, 5)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302908655320&#45;&gt;2302908654256 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>2302908655320&#45;&gt;2302908654256</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M142.5,-481.842C142.5,-474.012 142.5,-464.54 142.5,-456.282\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"146,-456.042 142.5,-446.042 139,-456.042 146,-456.042\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302908653920 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>2302908653920</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"277.5,-516 203.5,-516 203.5,-482 277.5,-482 277.5,-516\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"240.5\" y=\"-502.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">conv1.0.bias</text>\r\n",
       "<text text-anchor=\"middle\" x=\"240.5\" y=\"-489.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (16)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302908653920&#45;&gt;2302908654256 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2302908653920&#45;&gt;2302908654256</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M214.752,-481.842C199.723,-472.411 180.896,-460.596 166.229,-451.391\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"168.036,-448.393 157.705,-446.042 164.315,-454.322 168.036,-448.393\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943131856 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>2302943131856</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"333.5,-332 247.5,-332 247.5,-298 333.5,-298 333.5,-332\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-318.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">conv2.0.weight</text>\r\n",
       "<text text-anchor=\"middle\" x=\"290.5\" y=\"-305.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (32, 16, 5, 5)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943131856&#45;&gt;2302943132808 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>2302943131856&#45;&gt;2302943132808</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.5,-297.842C290.5,-290.012 290.5,-280.54 290.5,-272.282\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"294,-272.042 290.5,-262.042 287,-272.042 294,-272.042\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302908655376 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>2302908655376</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"425.5,-332 351.5,-332 351.5,-298 425.5,-298 425.5,-332\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"388.5\" y=\"-318.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">conv2.0.bias</text>\r\n",
       "<text text-anchor=\"middle\" x=\"388.5\" y=\"-305.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (32)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302908655376&#45;&gt;2302943132808 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>2302908655376&#45;&gt;2302943132808</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M362.752,-297.842C347.723,-288.411 328.896,-276.596 314.229,-267.391\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"316.036,-264.393 305.705,-262.042 312.315,-270.322 316.036,-264.393\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133256 -->\r\n",
       "<g id=\"node16\" class=\"node\"><title>2302943133256</title>\r\n",
       "<polygon fill=\"lightgrey\" stroke=\"black\" points=\"445,-78 374,-78 374,-57 445,-57 445,-78\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"409.5\" y=\"-64.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">TBackward</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133256&#45;&gt;2302943132976 -->\r\n",
       "<g id=\"edge15\" class=\"edge\"><title>2302943133256&#45;&gt;2302943132976</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M388.772,-56.9197C369.946,-48.219 341.95,-35.2792 320.649,-25.4343\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"321.936,-22.1734 311.39,-21.155 318.999,-28.5276 321.936,-22.1734\"/>\r\n",
       "</g>\r\n",
       "<!-- 2302943133200 -->\r\n",
       "<g id=\"node17\" class=\"node\"><title>2302943133200</title>\r\n",
       "<polygon fill=\"lightblue\" stroke=\"black\" points=\"465,-148 396,-148 396,-114 465,-114 465,-148\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"430.5\" y=\"-134.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">out.weight</text>\r\n",
       "<text text-anchor=\"middle\" x=\"430.5\" y=\"-121.4\" font-family=\"Times New Roman,serif\" font-size=\"12.00\"> (10, 1568)</text>\r\n",
       "</g>\r\n",
       "<!-- 2302943133200&#45;&gt;2302943133256 -->\r\n",
       "<g id=\"edge16\" class=\"edge\"><title>2302943133200&#45;&gt;2302943133256</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M424.982,-113.842C422.248,-105.834 418.927,-96.1082 416.063,-87.7205\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"419.302,-86.3744 412.758,-78.0419 412.677,-88.6364 419.302,-86.3744\"/>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.dot.Digraph at 0x218321b7f28>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cnn = CNN()\n",
    "x = torch.randn(1, 1, 28, 28).requires_grad_(True)\n",
    "y = cnn(x)\n",
    "make_dot(y, params=dict(list(cnn.named_parameters()) + [('x', x)]))   # 直接显示图像"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "inception = models.inception_v3()                              # 使用预训练模型\n",
    "new_model = nn.Sequential(*list(inception.children())[:-1])    # 除去最后一层\n",
    "pop_modules = new_model._modules.pop('13')                     # 移除13层辅助分类层\n",
    "# self.add_module('global average', nn.AvgPool2d(2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# x = torch.randn(1, 3, 224, 224)\n",
    "# y = new_model(x)\n",
    "# g = make_dot(y, params=dict(list(new_model.named_parameters()) + [('x', x)]))\n",
    "# g.view()             # 存为pdf，并打开，适用于比较大的模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 使用tensorboardX进行可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tensorboardX import SummaryWriter\n",
    "tensor_in = torch.randn([1,3,224,224])\n",
    "tensor_out = new_model(tensor_in)\n",
    "with SummaryWriter(comment='CNN') as w:\n",
    "    w.add_graph(new_model, (tensor_in,))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>tensorboard显示的效果</center>\n",
    "<img src='tensorboard.jpg' height='70%' width='70%'>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 总结\n",
    "- 可视化方法参考[github项目](https://github.com/lanpa/tensorboardX)，[PyTorch网络结构可视化](https://blog.csdn.net/xiaoxifei/article/details/82735355)\n",
    "\n",
    "- 在生成的runs文件夹所在路径下，打开命令行并运行`tensorboard --logdir runs`，将产生的网址复制到浏览器打开就可以查看tensorboard"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
